package com.edu.demo.utils;

import com.edu.demo.entity.LoginUser;
import com.edu.demo.entity.Student;
import com.edu.demo.entity.SysUser;
import com.edu.demo.entity.Teacher;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @ClassName: SecurityUtils
 * @Description:
 * @Author: jxw
 * @Date: 2023-01-28
 */
public class SecurityUtils {
    public static LoginUser getLoginUser(){
        return (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }


    public static Student getStudent(){
       return getLoginUser().getStudent();
    }

    public static Teacher getTeacher(){
        return getLoginUser().getTeacher();
    }

    public static SysUser getSysUser(){
       return getLoginUser().getSysUser();
    }

    public static Authentication getAuthentication() {
       return SecurityContextHolder.getContext().getAuthentication();
    }
}
